const electron = require('electron');
const path = require('path');

const { app } = electron;

const isWin = process.platform === 'win32';
const useEmbedFlash = !!process.env['KOOLEARN-USE-EMBED-FLASH'];

function applyFlash() {

    let dir = '';
    try {
        dir = !useEmbedFlash && isWin &&  app.getPath('pepperFlashSystemPlugin');
    } catch {
        //
    }


    console.log(dir);

    if (!dir) {
        let name;
        switch (process.platform) {
            case 'win32':
                name = process.arch === 'x64' ? 'windows/pepflashplayer64.dll' : "windows/pepflashplayer32.dll";
                break;
            case 'darwin':
                name = 'macosx/PepperFlashPlayer.plugin';
                break;
            case 'linux':
                name = 'libpepflashplayer.so';
                break;
            default:
                break;
        }

        dir = path.resolve(__dirname, '../..', 'flashPlugin', name);
    }

    console.log(dir);

    app.commandLine.appendSwitch('ppapi-flash-path', dir);
}

module.exports = { applyFlash };